package handler

import (
	"chat/chat-box/initernal/dto"
	"chat/chat-box/initernal/model"
	"chat/chat-box/pkg"
	"chat/chat-box/response"
	"github.com/gin-gonic/gin"
)

func Login(c *gin.Context) {

	var user model.User
	err := c.ShouldBind(&user)
	if err != nil {
		response.Error(c, "解析失败")
		return
	}
	err = dto.Login(&user, user.Tel)
	if err != nil {
		response.Error(c, "该账号未注册")
		return
	}
	var users model.User
	err = c.ShouldBind(&users)
	if err != nil {
		response.Error(c, "解析失败")
		return
	}
	if user.Password != users.Password {
		response.Error(c, "密码错误")
		return
	}
	handler, _ := pkg.TokenHandler(int(user.ID))
	response.Success(c, "登录成功", handler)

}
